﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/Website/Views/Shared/Product.Master"
    Inherits="System.Web.Mvc.ViewPage<ShopCarViewModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <% Html.RenderPartial("ShopCarMenu"); %>
    <% if (Model.CarList.Count == 0)
       { %>
    您的购物车还是空的，赶紧行动吧！
    <br />
    <br />
    <%=Html.ActionLink("找商品去", "Index", "Product") %>
    <% }
       else
       { %>
    <form method="post" action="" id="frm1">
    <div class="productContent">
        <table>
            <% foreach (var item in Model.CarList)
               { %>
            <tr>
                <td class="i">
                    <a href="<%=Url.Action("PreView","Product",new {ProductId = item.ProductId}) %>">
                        <img src="<%=Url.Action("Thumb", "Home",
                         new { h = 100, w = 75, s = string.Format("{0}/{1}/{2}", Model.ImageRoot, item.ProductId, item.ImageName) })%>"
                            alt="" />
                        <%=item.ProductName%></a>
                    <div>
                        品牌价: <del class="fontBold colorBlue">
                            <%= item.Price%></del>
                        <br />
                        优惠价: <strong class="colorOrange">
                            <%= (item.Price * item.MyDisCount).ToString("0.00")%></strong></div>
                </td>
                <td class="m">
                    <div class="colorRed  fontBold">
                        小计:
                        <%= (item.Price * item.MyDisCount * item.SalesCount).ToString("0.00")%></div>
                    <br />
                    <div class="colorOrange fontBold">
                        <%= item.Description.Replace("\n","&nbsp;") %></div>
                </td>
                <td>
                    <%= Html.TextBox("count", item.SalesCount, new { @class = "width50", autocomplete = "off", maxlength = 5 })%>
                    <input type="button" value="删除" name="btnDelete" />
                    <%= Html.Hidden("ProductId", item.ProductId, new { id = Guid.NewGuid() })%>
                    <%= Html.Hidden("Optional", item.KeyWords)%>
                </td>
            </tr>
            <% } %>
        </table>
    </div>
    <div class="textRight">
        共有 <strong class="colorRed">
            <%= Model.CarList.Sum(p=>p.SalesCount) %></strong> 件商品, 总金额: <strong class="colorRed font16">
                <%= (Model.CarList.Sum(p=>p.SalesCount * p.Price * p.MyDisCount)).ToString("0.00") %>
            </strong>元
    </div>
    <div class="textRight" style="margin: 10px 0px;">
        <div class="floatLeft">
            <input type="button" value="继续购物" id="btncontinue" />
        </div>
        <input type="submit" value="保存购物车" />
        <input type="submit" value="生成订单" name="setpNext" />
    </div>
    </form>
    <% } %>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server">
    <%= HtmlMetaHelper.HtmlTitle(ViewsResources.Shared.ShopCar)%>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="cssLink" runat="server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="jsLink" runat="server">
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="cssContent" runat="server">
    <style type="text/css">
        .productContent
        {
            border: solid 1px #D1EBFF;
            margin: 5px auto;
        }
        .productContent table
        {
            border: none;
            border-collapse: collapse;
            width: 100%;
        }
        .productContent td
        {
            border: solid 1px #fFF;
            background-color: #E2F2FF;
            overflow: hidden;
            padding: 5px;
            vertical-align: middle;
            text-align: center;
        }
        .productContent td.i
        {
            width: 300px;
            line-height: 1.5em;
            text-align: left;
        }
        .productContent td.i img
        {
            border: solid 1px #e9e9e9;
            float: left;
            margin-right: 10px;
        }
        .productContent td.i div
        {
            margin-top: 10px;
        }
        .productContent td.m li
        {
            margin: 5px 0px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="jsContent" runat="server">
    <script type="text/javascript">
        $(function () {
            $("#btncontinue").click(function () { document.location.href = '<%=Url.Action("Index", "Product") %>'; });
            $("#count").keypress(function (e) { return e.which >= 48 && e.which <= 57; });
            $(":input[name='btnDelete']").click(function () {
                if (confirm("删除确认!\n确定要删除吗?")) {
                    var productId = $(this).parents("tr").find(":hidden[name='ProductId']").val();
                    var optional = $(this).parents("tr").find(":hidden[name='Optional']").val();
                    $.post('<%= Url.Action("DeleteCarItem") %>', { ProductId: productId, optional: optional }, function () { location.replace(document.URL) });
                }
            });

        });
    </script>
</asp:Content>
